var express = require('express');
var router = express.Router();
let mongoose = require('mongoose');
let jsonwebtoken=require('jsonwebtoken');

// 试卷信息
//student:考生信息；   test:试卷信息
router.post('/get', async function(req,resp){
    let auth = req.header('Authorization');
    let token = auth.replace('Bearer ', '');
    let userObj = jsonwebtoken.verify(token, 'star').user;
    // find搜索对应id
    let tested = await mongoose.model('testedsModel').find({studentId:userObj._id}).populate('studentId').populate('testId').populate('typeId')
    
    let test = await mongoose.model('testsModel').find({}).populate('pointId').populate('exerciseId')
    // 输出试卷信息
    resp.send({
        code:1,
        massage:'获取试卷信息成功！',
        data: {tested,test}
    });
})

router.post('/testinfo', async function(req,resp){
    let {studentId,testId }= req.body;


    let student = await mongoose.model('studentsModel').find({_id:studentId})

    let test = await mongoose.model('testsModel').find({_id:testId})
    // 输出试卷信息
    
    resp.send({
        code:1,
        massage:'获取试卷信息成功！',
        data: {student,test}
    });
})



module.exports = router;
